package LeetCode;

public class LC_665_NondecreasingArray {

    public static void main(String[] args) {

    }

    class Solution {
        public boolean checkPossibility(int[] nums) {
            boolean modified = false;
            for (int i = 1; i < nums.length; i++) {
                if (nums[i] < nums[i - 1]) {
                    if (modified)
                        return false;
                    if (i < 2 || nums[i - 2] <= nums[i])
                        nums[i - 1] = nums[i];
                    else
                        nums[i] = nums[i - 1];
                    modified = true;
                }
            }
            return true;
        }
    }

}